﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Job.Web.Framework;
using Job.Entity;
using Job.Logic.Personal;

namespace Job.Web.userControls.Personal
{
    public partial class AdvanceHR : BaseCtrl
    {

        int _resumeId = myR["resumeid"].IntValue;
        int subjectid = myR["subjectid"].IntValue;

        PersonalLogic pl = new PersonalLogic();

        private void ShowMessage(string message)
        {
            this.message.InnerHtml = "<font color=red>" + message + "</font>";
            this.message.Visible = true;
            this.message.Height = "30px";
            this.message.VAlign = "middle";
        }


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                this.LoadData();
            }
        }

        private void LoadData()
        {
            try
            {
                JobPersonAdvance adv = pl.GetAdvance(_resumeId);
                string time = string.Empty;

                if (adv != null && adv.LeaveTime.HasValue)
                    time = adv.LeaveTime.Value.ToString();
                WebCommon.SetDropDownFromDict(ddlTime, time, Constants.GetDictionaryCode(Constants.DictionaryType.PARTICIPATE_LEN), true);

                if (adv != null)
                {
                    txtAllowance.Text = adv.Allowance.HasValue == true ? adv.Allowance.Value.ToString() : "";
                    txtBaseWage.Text = adv.BaseWage.HasValue == true ? adv.BaseWage.Value.ToString() : "";
                    txtBonus.Text = adv.Bonus.HasValue == true ? adv.Bonus.Value.ToString() : "";
                    txtStock.Text = adv.Stock;
                }
            }
            catch (Exception ex)
            {

                ShowMessage("查询失败：<br>" + ex.Message);
                Logger.WriteLog("高级人才查询失败：" + ex.Message);
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                JobPersonAdvance adv = pl.GetAdvance(_resumeId);
                adv.Stock = txtStock.Text;
                adv.PersonInfoId = _resumeId;
                adv.LeaveTime = Convert.ToInt32(ddlTime.SelectedValue);
                Decimal bouns = 0m;
                Decimal basewage = 0m;
                Decimal all = 0m;
                Decimal.TryParse(txtBonus.Text.Trim(), out bouns);
                Decimal.TryParse(txtBaseWage.Text.Trim(), out basewage);
                Decimal.TryParse(txtAllowance.Text.Trim(), out all);
                if (bouns > 0)
                    adv.Bonus = bouns;
                if (all > 0)
                    adv.Allowance = all;
                if (basewage > 0)
                    adv.BaseWage = basewage;

                if (adv.PersonAdvanceId > 0)
                {
                    pl.UpdateAdvance(adv);
                }
                else
                {
                    pl.InsertAdvance(adv);
                }
            }
            catch (Exception ex)
            {

                ShowMessage("保存失败：<br>" + ex.Message);
                Logger.WriteLog("高级人才保存失败：" + ex.Message);
            }
        }
    }
}